function graphsVec=plotColForAllPages(varMat,inStru,nameStru)
% =========================================================================
%% plotColumnsPerPage(varMat,obsnames,shonames,title,offset);
%
% Generate a subplot for each column of varMat, plot the corresponding
% columns for each page. Use for instance to compare the contribution of
% each shock across different models, where the different models are in
% Pages 
% 
% 1) *varMat*      [nobs NC NP] matrix 
%
% 3) *inStru*      Structure with all inputs for the graph, 
%                  including 
% Requires *inStru.legend*=[NP 1] with description of each page 
%          *inStru.suptitle* String to put on the top of each graph 

% Optional 
%  .'xaxis'        Vector of X-axis 
%  .'suptitle'     String to add to the dimension being ploted in titles 
% *nameStru*  .colNames 
%                .pageNames
%
%
% Alejandro Justiniano January 21st 2010
% =========================================================================
[NR NC NP]=size(varMat); 
%% 3. Defaults
[~,inStru]=ch_field(inStru,'xOffset',0.1); 
[~,inStru]=ch_field(inStru,'yOffset',0.1); 
[~,inStru]=ch_field(inStru,'flagBoxOff',1); 
[~,inStru]=ch_field(inStru,'lineWidths',[1.5 2.5]); 
[~,inStru]=ch_field(inStru,'colors',[0 0 1;0 0 0]); 
[~,inStru]=ch_field(inStru,'NFigRows',5); 
[~,inStru]=ch_field(inStru,'NFigCols',2); 
[~,inStru]=ch_field(inStru,'suptitle',[]); 
[~,inStru]=ch_field(inStru,'suptitleFlush','left'); 
[~,inStru]=ch_field(inStru,'xaxis',(1:NR)'); 
inStru=plotAssignDefaults(inStru);
%% 2. Check sizes
if length(nameStru.colNames)~=NC; 
    error('colNames does not match number of columns in CMAT'); 
end 
if length(nameStru.pageNames)~=NP; 
    error('pageNames does not match number of pages in CMAT'); 
end 
if isfield(inStru,'legend')==false;
    error('Need provide inStru.legend');
end
% if isfield(inStru,'orgBy')==false; 
%     disp('inStru.orgBy must be cols or pages'); 
%     error('Need provide inStru.orgBy'); 
% end 
%% Organize Plots by Columns or Pages? 
%if strmatch(upper(inStru.orgBy),'COLS'); 
%    flagOrgByCol=1; 
if ~isempty(inStru.axesFontSize); 
    set(0,'DefaultAxesFontSize',inStru.axesFontSize);
end 

%% Graph Settings 
NRows=inStru.NFigRows;
NCols=inStru.NFigCols;
graphsVec =zeros(ceil(NC/(NRows*NCols)),1);

ISubplots=0;
IGraphs  =0;
ICounter =0;
for jj=1:NC    
    if ISubplots==0
        IGraphs=IGraphs+1;
        graphsVec(IGraphs,1)=figure;
    end
    ISubplots=ISubplots+1;
    ICounter =ICounter+1;
    subplot(NRows,NCols,ISubplots);
    if ISubplots==NRows*NCols || jj==NC
        inStru.flagNoLegend=0;
    else
        inStru.flagNoLegend=1;
    end 
    %% Extract column JJ Across Pages
    tempMat=squeeze(varMat(:,jj,:));
    tempTit=nameStru.colNames{jj};
    %% SUPTITLE HERE MUST BE THE NAME OF THS SHOCK BEING PLOTTED
    tempSuptit=char(inStru.suptitle);
    [~,~,~]=plot3sampSub(inStru.xaxis,tempMat,tempTit,1,inStru);
    if ISubplots==NRows*NCols %|| jj==NCols
        ISubplots=0;
        if size(graphsVec,1)==1
            supHand=suptitle(tempSuptit);
        else
            supHand=suptitle([tempSuptit,'   (',num2str(IGraphs),' of ',...
                num2str(size(graphsVec,1)),')']);
        end
        set(supHand,'FontSize',inStru.suptitleFontSize,'FontName',inStru.FontName,...
            'FontWeight','Bold');
        set(graphsVec(IGraphs),'PaperPosition',inStru.paperPosition)
    end
end
if ~isempty(inStru.axesFontSize);
    set(0,'DefaultAxesFontSize','remove');
end
end